import { Store } from "../../core";

import PrintButton from "./PrintButton";
import PrintStatus from "./PrintStatus";
import StoreProps from "./StoreProps";
import { FC, ReactElement } from "react";

export interface RenderPrintProps {
  onClick: () => void;
}

type RenderPrint = (props: RenderPrintProps) => ReactElement;

export interface PrintProps {
  children?: RenderPrint;
}

const Print: FC<{
  children?: RenderPrint;
  store: Store<StoreProps>;
}> = ({ children, store }) => {
  const print = () => {
    store.update("printStatus", PrintStatus.Preparing);
  };

  const defaultChildren = (props: RenderPrintProps) => (
    <PrintButton onClick={props.onClick} />
  );
  const render = children || defaultChildren;

  return render({
    onClick: print,
  });
};

export default Print;
